<?php
namespace backend\model;
use common\model\common_model;
/**
 * admin_role模型数据库操作类
 */

class admin_role extends common_model {
    const ID_SUPERADMIN = 1;

	public $table_name = 'admin_role';
	public $category = '';
	public $_pk  = 'role_id';

	const STATUS_YES       = 1;
	const STATUS_DISABLED = 2;
	const STATUS_DELETED  = -1;

	const ROLE_ID_SUPERADMIN = 1;

    /**
     * 获取常量的字符数值
     * @param string $field
     * @param string $value
     * @return mixed|string
     */
	public static function getConstValue($field='status',$value='all')
    {
        $m = [];
        if($field == 'status'){
            $m[$field] = [
                self::STATUS_YES          =>  '正常',
                self::STATUS_DISABLED      =>  '禁用',
                self::STATUS_DELETED      =>  '删除',
            ];
        }
        if( $value == 'all' ){
            return $m[$field];
        }
        return isset($m[$field][$value]) ? $m[$field][$value] : '';
    }
	public function __construct() {
		$this->db_config = load_config('database');
		$this->db_setting = 'default';
		parent::__construct();
	    
	}

    /**
     * 删除某一个管理员角色账号
     * @param $role_id
     * @return bool
     * @throws \Exception
     */
	public function deleteRole($role_id)
    {
        if(empty($role_id)){
            throw new \Exception('role_id不能为空',-201);
        }
        if($role_id == 1){
            throw new \Exception('role_id不能为1',-205);
        }
        $op = $this->update(['role_status'=>self::STATUS_DELETED],['role_id'=>$role_id]);
        if(!$op){
            throw new \Exception($this->getError(),$this->getErrorNo());
        }
        return true;
    }
}
?>